package com.come4loves.core.comunicate;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
/**
 * 白名单配置
 * @author jerry
 *
 */
public class WhiteListConfig {
	@Autowired(required=false)
	private Set<String> adminIP = new HashSet<String>();
	@Autowired(required=false)
	private Set<String> gameIP = new HashSet<String>();
	@Autowired(required=false)
	private Set<String> allowUID = new HashSet<String>();
	private boolean open;
	
	public WhiteListConfig(boolean open) {
		this.open = open;
	}
	
	/**
	 * 是否允许的管理ip
	 * @param ip
	 * @return
	 */
	public boolean allowAdmin(String ip) {
		if (!open) {
			return true;
		}
		if (adminIP == null || adminIP.isEmpty()) {
			return true;
		}
		return this.adminIP.contains(ip);
	}
	/**
	 * 是否允许的游戏ip
	 * @param ip
	 * @return
	 */
	public boolean allowGame(String ip) {
		if (!open) {
			return true;
		}
		if (gameIP == null || gameIP.isEmpty()) {
			return true;
		}
		return this.gameIP.contains(ip);
	}
	/**
	 * 是否允许的uid
	 * @param uid
	 * @return
	 */
	public boolean allowUID(String uid) {
		if (!open) {
			return true;
		}
		if (allowUID == null || allowUID.isEmpty()) {
			return true;
		}
		return this.allowUID.contains(uid);
	}
	/**
	 * 添加admin端口ip
	 * @param adminIP
	 */
	public void addAdminIP(String adminIP) {
		this.adminIP.add(adminIP);
	}
	/**
	 * 删除admim端口ip
	 * @param adminIP
	 */
	public void removeAdminIP(String adminIP) {
		this.adminIP.remove(adminIP);
	}
	/**
	 * 添加游戏端口ip
	 * @param gameIP
	 */
	public void addGameIP(String gameIP) {
		this.gameIP.add(gameIP);
	}
	/**
	 * 删除游戏端口ip
	 * @param gameIP
	 */
	public void removeGameIP(String gameIP) {
		this.gameIP.remove(gameIP);
	}
	/**
	 * 添加可访问uid
	 * @param uid
	 */
	public void addUID(String uid) {
		this.allowUID.add(uid);
	}
	/**
	 * 删除可访问uid
	 * @param uid
	 */
	public void removeUID(String uid) {
		this.allowUID.add(uid);
	}
	
}
